<include file="Public:head" />
<div class="col-xs-12">
    <div class="tabbable">
        <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab">
            <li class="active">
                <a href="#home" data-toggle="tab">菜单列表</a></li>
            <li>
                <a href="javascript:;" onclick="add()">添加菜单</a></li>
        </ul>
        <div class="tab-content">
            <form class="layui-form" action="{:U('Admin/Nav/order')}" method="post">
                <table class="layui-table">
                    <tr>
                        <th width="5%">排序</th>
                        <th>菜单名</th>
                        <th>连接</th>
                        <th>操作</th></tr>
                    <foreach name="data" item="v">
                        <tr>
                            <td>
                                <input class="input-medium" style="width:40px;height:25px;text-align: center;border: 1px solid #e6e6e6;" type="text" name="{$v['id']}" value="{$v['order_number']}"></td>
                            <td>{$v['_name']}</td>
                            <td>{$v['mca']}</td>
                            <td>
                                <a href="javascript:;" navId="{$v['id']}" navName="{$v['name']}" onclick="add_child(this)">添加子菜单</a>|
                                <a href="javascript:;" navId="{$v['id']}" navName="{$v['name']}" navMca="{$v['mca']}" navIco="{$v['ico']}" onclick="edit(this)">修改</a>|
                                <a href="javascript:;" onclick="del('{:U('Admin/Nav/delete')}',{$v['id']})">删除</a>
                            </td>
                        </tr>
                    </foreach>
                    <tr>
                        <th>
                            <button class="layui-btn layui-btn-small layui-btn-normal" lay-submit lay-filter="orderNav">排序</button>
                        </th>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加菜单</h4></div>
            <div class="modal-body">
                <form id="bjy-form" class="layui-form" action="{:U('Admin/Nav/add')}" method="post">
                    <input type="hidden" name="pid" value="0">
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单名：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="请输入菜单名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">连接：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="mca" placeholder="Admin/Nav/index" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">输入模块/控制器/方法 例如 Admin/Nav/index</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图标：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ico" placeholder="图标" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux"><a href="http://fontawesome.dashgame.com/" target="_blank">font-awesome</a> 图标 输入fa fa- 后边的即可</div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" lay-submit lay-filter="addNav">添加</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改菜单</h4></div>
            <div class="modal-body">
                <form id="bjy-form" class="layui-form" action="{:U('Admin/Nav/edit')}" method="post">
                    <input type="hidden" name="id">
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单名：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="请输入菜单名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">连接：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="mca" placeholder="Admin/Nav/index" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">输入模块/控制器/方法 例如 Admin/Nav/index</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图标：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ico" placeholder="请输入图标" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux"><a href="http://fontawesome.dashgame.com/" target="_blank">font-awesome</a> 图标 输入fa fa- 后边的即可</div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" lay-submit lay-filter="editNav">修改</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    .tab-content .layui-table td{
        text-align: left;
    }
</style>
<script>

    $(document).ready(function(){
        layui.use('form', function(){
            var form = layui.form;
            // 验证
            form.verify({
                // money:[/^(([1-9]\d*)|\d)(\.\d{1,2})?$/,"请输入正确的价格！"],
            }); 
            //监听提交排序菜单
            form.on('submit(orderNav)', function(data){
                $(data.form).ajaxSubmit({
                    url:"{:U('Admin/Nav/order')}",
                    type: 'post',
                    beforeSubmit:function(ormData,jqForm,options){
                        //加载层-风格4
                        layer.msg('加载中...', {
                          icon: 16,
                          shade: 0.2,
                          time:0,
                        });
                    },
                    success:function(responseText,statusText){
                        layer.closeAll();
                        if(responseText.status == 1){
                            layer.msg(responseText.info, {icon: 6,shade: 0.2,time:1000},function(){
                                location.href = responseText.url;
                            });
                        }else{
                            layer.msg(responseText.info, {icon: 5,shade: 0.2,time:1000});
                        }
                    },
                });
                //layer.msg(JSON.stringify(data.field));
                return false;
            });     
            //监听提交修改菜单
            form.on('submit(editNav)', function(data){
                $(data.form).ajaxSubmit({
                    url:"{:U('Admin/Nav/edit')}",
                    type: 'post',
                    beforeSubmit:function(ormData,jqForm,options){
                        //加载层-风格4
                        layer.msg('加载中...', {
                          icon: 16,
                          shade: 0.2,
                          time:0,
                        });
                    },
                    success:function(responseText,statusText){
                        layer.closeAll();
                        if(responseText.status == 1){
                            layer.msg(responseText.info, {icon: 6,shade: 0.2,time:1000},function(){
                                location.href = responseText.url;
                            });
                        }else{
                            layer.msg(responseText.info, {icon: 5,shade: 0.2,time:1000});
                        }
                    },
                });
                //layer.msg(JSON.stringify(data.field));
                return false;
            });
            //监听提交添加菜单
            form.on('submit(addNav)', function(data){
                $(data.form).ajaxSubmit({
                    url:"{:U('Admin/Nav/add')}",
                    type: 'post',
                    beforeSubmit:function(ormData,jqForm,options){
                        //加载层-风格4
                        layer.msg('加载中...', {
                          icon: 16,
                          shade: 0.2,
                          time:0,
                        });
                    },
                    success:function(responseText,statusText){
                        layer.closeAll();
                        if(responseText.status == 1){
                            layer.msg(responseText.info, {icon: 6,shade: 0.2,time:1000},function(){
                                location.href = responseText.url;
                            });
                        }else{
                            layer.msg(responseText.info, {icon: 5,shade: 0.2,time:1000});
                        }
                    },
                });
                //layer.msg(JSON.stringify(data.field));
                return false;
            });
        });
    });

    // 添加菜单
    function add(){
        $("input[name='name'],input[name='mca']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var navId=$(obj).attr('navId');
        $("input[name='pid']").val(navId);
        $("input[name='name']").val('');
        $("input[name='mca']").val('');
        $("input[name='ico']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var navId=$(obj).attr('navId');
        var navName=$(obj).attr('navName');
        var navMca=$(obj).attr('navMca');
        var navIco=$(obj).attr('navIco');
        $("input[name='id']").val(navId);
        $("input[name='name']").val(navName);
        $("input[name='mca']").val(navMca);
        $("input[name='ico']").val(navIco);
        $('#bjy-edit').modal('show');
    }
</script>
<include file="Public:foot" />